#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>
#include <linux/if_ether.h>
#include <linux/if.h>



int main(){
    int sockfd ;
    struct ifreq ifr;
    char *interface_name = "ens32";
    if(( sockfd = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_IP)))<0){
        perror(strerror(errno));
        exit(1);
    };

    strncpy(ifr.ifr_name, interface_name, IFNAMSIZ);
    if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) == -1) {
        perror("ioctl SIOCGIFFLAGS");
        close(sockfd);
        exit(EXIT_FAILURE);
    }
    ifr.ifr_flags |= IFF_PROMISC;
    if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) == -1) {
        perror("ioctl SIOCSIFFLAGS");
        close(sockfd);
        exit(EXIT_FAILURE);
    }

    while (1)
    {
        /* code */
        unsigned char buf [16*10];
        int count = read(sockfd,buf,sizeof(buf))
        ;
        printf("read count %d",count);
        for (int i=0;i<count;i++){
            if (i%16==0){
             printf("\n");   
            }
            printf("0x%02x ",buf[i]);
            
        }
        printf("\n");
        sleep(1);
    }
    

}